package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo04FlatMap {
  def main(args: Array[String]): Unit = {
    /**
     * flatMap：转换算子，需要接收一个函数f
     * 返回值类型有特殊要求，必须是数组或者是集合类
     * 会对返回的数组或者是集合进行扁平化处理，即展开
     * 传入一条数据返回多条数据
     */
    val conf: SparkConf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("Demo04FlatMap")

    val sc: SparkContext = new SparkContext(conf)

    val wordList: List[String] = List[String]("java,java,java", "scala,scala", "python")
    val lineRDD: RDD[String] = sc.parallelize(wordList)
    lineRDD.flatMap(line=>line.split(",")).foreach(println)


  }

}
